home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 551-575 / disk_562 / intuisup / library / source.lzh / libstartup.asm < prev    next >
Assembly Source File  |  1991-07-14  |  8KB  |  354 lines

  1.         *************************************
  2.         *                                   *
  3.         *       Intuition Support v2.0      *
  4.         *   by Torsten Jürgeleit in 05/91   *
  5.         *                                   *
  6.         *        Library startup code       *
  7.         *                                   *
  8.         *************************************
  9.  
  10. ;---------------------------------------------------------------------------
  11. ; Includes
  12. ;---------------------------------------------------------------------------
  13.  
  14.     NOLIST
  15.     INCLUDE    <exec/types.i>
  16.     INCLUDE <exec/libraries.i>
  17.     INCLUDE <exec/initializers.i>
  18.     INCLUDE <exec/resident.i>
  19.     INCLUDE    "libdata.i"
  20.     LIST
  21.  
  22. ;---------------------------------------------------------------------------
  23. ; External definitions
  24. ;---------------------------------------------------------------------------
  25.  
  26.     XDEF    .begin
  27.     XDEF    _LibOpen
  28.     XDEF    _LibClose
  29.     XDEF    _LibExpunge
  30.     XDEF    _LibNull
  31.     XDEF    _geta4
  32.     XDEF    _SysBase
  33.     XDEF    _DosBase
  34.     XDEF    _GfxBase
  35.     XDEF    _IntuitionBase
  36.     XDEF    _LayersBase
  37.  
  38. ;---------------------------------------------------------------------------
  39. ; External references
  40. ;---------------------------------------------------------------------------
  41.  
  42.     XREF    _FuncTable
  43.     XREF    __H1_org
  44.  
  45. ;---------------------------------------------------------------------------
  46. ; Support macros
  47. ;---------------------------------------------------------------------------
  48.  
  49. CALL    MACRO
  50.     XREF    \1
  51.     jsr    \1
  52.     ENDM
  53.  
  54. CALLSYS    MACRO
  55.     XREF    _LVO\1
  56.     jsr    _LVO\1(a6)
  57.     ENDM
  58.  
  59. PUSH    MACRO
  60.     movem.l    \1,-(sp)
  61.     ENDM
  62.  
  63. PULL    MACRO
  64.     movem.l    (sp)+,\1
  65.     ENDM
  66.  
  67. ;---------------------------------------------------------------------------
  68. ; First executable location -> do nothing
  69. ;---------------------------------------------------------------------------
  70.  
  71.     SECTION IntuitionSupport,CODE
  72. .begin:
  73.     moveq    #0,d0
  74.     rts
  75.  
  76. ;---------------------------------------------------------------------------
  77. ; RomTag structure
  78. ;---------------------------------------------------------------------------
  79.  
  80. RomTag:                ; STRUCTURE RT,0
  81.     dc.w    RTC_MATCHWORD    ;    UWORD RT_MATCHWORD
  82.     dc.l    RomTag        ;    APTR  RT_MATCHTAG
  83.     dc.l    EndCode        ;    APTR  RT_ENDSKIP
  84.     dc.b    RTF_AUTOINIT    ;    UBYTE RT_FLAGS
  85.     dc.b    VERSION        ;    UBYTE RT_VERSION
  86.     dc.b    NT_LIBRARY    ;    UBYTE RT_TYPE
  87.     dc.b    PRIORITY    ;    BYTE  RT_PRI
  88.     dc.l    LibName        ;    APTR  RT_NAME
  89.     dc.l    LibID        ;    APTR  RT_IDSTRING
  90.     dc.l    InitTable    ;    APTR  RT_INIT
  91.  
  92. ;---------------------------------------------------------------------------
  93. ; Library strings
  94. ;---------------------------------------------------------------------------
  95.  
  96. LibName:    LIB_NAME
  97. LibTag:        dc.b    0,"$VER: "
  98. LibID:        LIB_ID
  99.         INCLUDE <compile_date.i>
  100. DosName:    dc.b    "dos.library",0
  101. GfxName:    dc.b    "graphics.library",0
  102. IntuitionName:    dc.b    "intuition.library",0
  103. LayersName:    dc.b    "layers.library",0
  104.     EVEN
  105.  
  106. ;---------------------------------------------------------------------------
  107. ; Library tables
  108. ;---------------------------------------------------------------------------
  109.  
  110. InitTable:
  111.     dc.l    LIB_SIZEOF    ; size of library base data space
  112.     dc.l    _FuncTable    ; pointer to function initializers
  113.     dc.l    DataTable    ; pointer to data initializers
  114.     dc.l    InitRoutine    ; routine to run
  115.  
  116. DataTable:
  117.     INITBYTE    LN_TYPE,NT_LIBRARY
  118.     INITLONG    LN_NAME,LibName
  119.     INITBYTE    LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  120.     INITWORD    LIB_VERSION,VERSION
  121.     INITWORD    LIB_REVISION,REVISION
  122.     INITLONG    LIB_IDSTRING,LibID
  123.     dc.l        0
  124.  
  125. ;---------------------------------------------------------------------------
  126. ; Library init routine
  127. ;
  128. ; Input: d0 = library ptr       Return: d0 = library ptr or NULL if error
  129. ;     a0 = seglist ptr
  130. ;     a6 = SysBase
  131. ;---------------------------------------------------------------------------
  132.  
  133. InitRoutine:
  134.     PUSH    d2/a2-a3
  135.  
  136.     ; --- save library ptr
  137.     move.l    d0,a2
  138.  
  139.     ; --- init important ptrs
  140.     lea    SegList(pc),a3        ; a3 := start of ptr buffer
  141.     move.l    a0,(a3)+        ; init SegList
  142.     move.l    a6,(a3)+        ; init _SysBase
  143.  
  144.     ; --- open libraries
  145.     lea    DosName(pc),a1
  146.     moveq    #0,d0
  147.     CALLSYS    OpenLibrary
  148.     move.l    d0,(a3)+
  149.     beq    InitRoutine_Error
  150.  
  151.     lea    GfxName(pc),a1
  152.     moveq    #0,d0
  153.     CALLSYS    OpenLibrary
  154.     move.l    d0,(a3)+
  155.     beq    InitRoutine_CloseDosLib
  156.  
  157.     lea    IntuitionName(pc),a1
  158.     moveq    #0,d0
  159.     CALLSYS    OpenLibrary
  160.     move.l    d0,(a3)+
  161.     beq    InitRoutine_CloseGfxLib
  162.  
  163.     lea    LayersName(pc),a1
  164.     moveq    #0,d0
  165.     CALLSYS    OpenLibrary
  166.     move.l    d0,(a3)+
  167.     beq    InitRoutine_CloseGfxLib
  168.  
  169.     ; --- call library specific init routine
  170.     PUSH    a2-a4/a6
  171.     bsr    _geta4
  172.     CALL    _LibInit
  173.     PULL    a2-a4/a6
  174.     tst.w    d0            ; check return code (BOOL)
  175.     beq    InitRoutine_CloseIntuitionLib
  176.  
  177.     move.l    a2,d0            ; set return code -> ok
  178.  
  179. InitRoutine_Exit:
  180.     PULL    d2/a2-a3
  181.     rts
  182.  
  183. InitRoutine_CloseLayersLib:
  184.     moveq    #3,d2
  185.     bra    InitRoutine_CloseLibs
  186.  
  187. InitRoutine_CloseIntuitionLib:
  188.     moveq    #2,d2
  189.     bra    InitRoutine_CloseLibs
  190.  
  191. InitRoutine_CloseGfxLib:
  192.     moveq    #1,d2
  193.     bra    InitRoutine_CloseLibs
  194.  
  195. InitRoutine_CloseDosLib:
  196.     moveq    #0,d2
  197.  
  198. InitRoutine_CloseLibs:
  199.     move.l    -(a3),a1
  200.     CALLSYS    CloseLibrary
  201.     dbra    d2,InitRoutine_CloseLibs
  202.  
  203. InitRoutine_Error:
  204.     moveq    #0,d0            ; set return code -> error
  205.     bra    InitRoutine_Exit
  206.  
  207. ;---------------------------------------------------------------------------
  208. ; Library open routine
  209. ;
  210. ; Input: d0 = version        Return: d0 = library ptr or NULL if error
  211. ;     a6 = library ptr
  212. ;---------------------------------------------------------------------------
  213.  
  214. _LibOpen:
  215.     ; --- mark us as having another opener
  216.     addq.w    #1,LIB_OPENCNT(a6)
  217.  
  218.     ; --- prevent delayed expunges
  219.     bclr    #LIBB_DELEXP,LIB_FLAGS(a6)
  220.  
  221.     move.l    a6,d0            ; set return code -> ok
  222.     rts
  223.  
  224. ;---------------------------------------------------------------------------
  225. ; Library close routine
  226. ;
  227. ; Input: a6 = library ptr    Return: d0 = NULL or seglist ptr if expunge
  228. ;---------------------------------------------------------------------------
  229.  
  230. _LibClose:
  231.     ; --- set the return value for no expunge
  232.     moveq    #0,d0
  233.  
  234.     ; --- mark us as having one fewer openers
  235.     subq.w    #1,LIB_OPENCNT(a6)
  236.  
  237.     ; --- see if there is anyone left with us open
  238.     bne.s    LibClose_Exit
  239.  
  240.     ; --- see if we have a delayed expunge pending
  241.     btst    #LIBB_DELEXP,LIB_FLAGS(a6)
  242.     beq.s    LibClose_Exit
  243.  
  244.     ; --- do the expunge
  245.     bsr    _LibExpunge
  246.  
  247. LibClose_Exit:
  248.     rts
  249.  
  250. ;---------------------------------------------------------------------------
  251. ; Library open routine
  252. ;
  253. ; Input: a6 = library ptr    Return: d0 = NULL or seglist ptr if expunge
  254. ;---------------------------------------------------------------------------
  255.  
  256. _LibExpunge:
  257.     PUSH    d2/a5-a6
  258.  
  259.     ; --- init some regs
  260.     move.l    a6,a5            ; a5 := library ptr
  261.     move.l    _SysBase(pc),a6        ; a6 := SysBase
  262.    
  263.     ; --- see if anyone has us open
  264.     tst.w    LIB_OPENCNT(a5)
  265.     beq    LibExpunge_DoExpunge
  266.  
  267.     ; --- it is still open.  set the delayed expunge flag
  268.     bset    #LIBB_DELEXP,LIB_FLAGS(a5)
  269.     moveq    #0,d0            ; set reurn code -> no expunge
  270.     bra.s    LibExpunge_Exit
  271.  
  272. LibExpunge_DoExpunge:
  273.     ; --- unlink from library list
  274.     move.l    a5,a1
  275.     CALLSYS    Remove
  276.    
  277.     ; --- library specific expunge routine
  278.     PUSH    a4/a6
  279.     bsr    _geta4
  280.     CALL    _LibFree
  281.     PULL    a4/a6
  282.  
  283.     ; --- free our memory
  284.     moveq    #0,d0
  285.     move.l    a5,a1
  286.     move.w    LIB_NEGSIZE(a5),d0
  287.     sub.l    d0,a1
  288.     add.w    LIB_POSSIZE(a5),d0
  289.     CALLSYS    FreeMem
  290.  
  291.     ; --- close libraries
  292.     lea    _DosBase(pc),a5
  293.     moveq    #3,d2
  294.  
  295. LibExpunge_CloseLoop:
  296.     move.l    (a5)+,a1
  297.     CALLSYS    CloseLibrary
  298.     dbra    d2,LibExpunge_CloseLoop
  299.  
  300.     ; --- set up our return value
  301.     move.l    SegList(pc),d0
  302.  
  303. LibExpunge_Exit:
  304.     PULL    d2/a5-a6
  305.     rts
  306.  
  307. ;---------------------------------------------------------------------------
  308. ; Library null routine
  309. ;
  310. ; Input: a6 = library ptr
  311. ;---------------------------------------------------------------------------
  312.  
  313. _LibNull:
  314.     moveq    #0,d0
  315.     rts
  316.  
  317. ;---------------------------------------------------------------------------
  318. ; Init data segment ptr a4 - needed for small data memory model
  319. ;---------------------------------------------------------------------------
  320.  
  321. _geta4:
  322.     FAR    CODE
  323.     FAR    DATA
  324.  
  325.     lea    __H1_org+32766,a4
  326.  
  327.     NEAR    DATA
  328.     NEAR    CODE
  329.     rts
  330.  
  331. ;---------------------------------------------------------------------------
  332. ; Important ptrs -> init by Init
  333. ;---------------------------------------------------------------------------
  334.  
  335. SegList:
  336.     dc.l    0
  337. _SysBase:
  338.     dc.l    0
  339. _DosBase:
  340.     dc.l    0
  341. _GfxBase:
  342.     dc.l    0
  343. _IntuitionBase:
  344.     dc.l    0
  345. _LayersBase:
  346.     dc.l    0
  347.  
  348. ;---------------------------------------------------------------------------
  349. ; Skip label for RomTag
  350. ;---------------------------------------------------------------------------
  351.  
  352. EndCode:
  353.     END
  354.